package com.ibeeking.found.workflow.b.rest.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ibeeking.found.common.utils.UserUtils;
import com.ibeeking.found.workflow.b.rest.service.FlowTaskExtService;
import com.ibeeking.found.workflow.service.common.dos.FlowTaskExt;
import com.ibeeking.found.workflow.service.mapper.BaseDaoMapper;
import com.ibeeking.found.workflow.service.mapper.FlowTaskExtMapper;
import com.ibeeking.nematos.utils.data.Collections3;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 流程任务扩展数据操作服务类。
 *
 * @author Jerry
 * @date 2021-06-06
 */
@Slf4j
@Service("flowTaskExtService")
public class FlowTaskExtServiceImplAbstract extends AbstractBaseService<FlowTaskExt, String> implements FlowTaskExtService {

    @Resource
    private FlowTaskExtMapper flowTaskExtMapper;

    /**
     * 返回当前Service的主表Mapper对象。
     *
     * @return 主表Mapper对象。
     */
    @Override
    protected BaseDaoMapper<FlowTaskExt> mapper() {
        return flowTaskExtMapper;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveBatch(List<FlowTaskExt> flowTaskExtList) {
        Integer tenantId = UserUtils.getTenantid();
        if (Collections3.isNotEmpty(flowTaskExtList)) {
            flowTaskExtMapper.insertList(tenantId, flowTaskExtList);
        }
    }

    @Override
    public FlowTaskExt getByProcessDefinitionIdAndTaskId(String processDefinitionId, String taskId) {
        FlowTaskExt filter = new FlowTaskExt();
        filter.setProcessDefinitionId(processDefinitionId);
        filter.setTaskId(taskId);
        return flowTaskExtMapper.selectOne(new QueryWrapper<>(filter));
    }

    @Override
    public List<FlowTaskExt> getByProcessDefinitionId(String processDefinitionId) {
        FlowTaskExt filter = new FlowTaskExt();
        filter.setProcessDefinitionId(processDefinitionId);
        return flowTaskExtMapper.selectList(new QueryWrapper<>(filter));
    }
}
